package com.dhb.pattern.template;

import javax.sql.DataSource;
import java.sql.ResultSet;
import java.util.List;

/**
 * 功能描述：
 * 创建人：citymoon
 * 创建日期：2019/5/23
 */
public class MemberDao extends JdbcTemplate {

    public MemberDao(DataSource dataSource) {
        super(dataSource);
    }

    public List<?> selectAll(){

        String sql = "select * from member";
        return super.executeQuery(sql, new RowMapper<Member>() {

            @Override
            public Member mapRow(ResultSet rs, int rowNum) throws Exception {
                Member member = new Member();

                member.setUserName(rs.getString("username"));
                member.setPassword(rs.getString("password"));
                member.setNickName(rs.getString("nickname"));
                member.setAge(rs.getInt("age"));
                member.setAddr(rs.getString("addr"));
                return member;
            }
        }, null);
    }
}
